/**    
 * 文件名：Ex5ROLogo.java    
 *    
 * 版本信息：    
 * 日期：2014年3月7日    
 * xyj 足下 xyj 2014     
 * 版权所有    
 *    
 */
package opencvtest.chapter02;

import static com.googlecode.javacv.cpp.opencv_core.cvCopy;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_COLOR;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_GRAYSCALE;
import static opencvtest.OpenCVUtils.loadAndShowOrExit;
import static opencvtest.OpenCVUtils.show;

import java.io.File;

import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_core.IplROI;

/**
 * @项目名称：opencv-test
 * @类名称：Ex5ROLogo
 * @类描述：
 * @创建人：zhuyi
 * @创建时间：2014年3月7日 下午4:39:55
 * @修改人：zhuyi
 * @修改时间：2014年3月7日 下午4:39:55
 * @修改备注：
 * @version
 * 
 */
public class Ex5ROLogo {

    public static void main(String[] args) {

        IplImage logo = loadAndShowOrExit(new File("data/logo.bmp"), CV_LOAD_IMAGE_COLOR);
        IplImage mask = loadAndShowOrExit(new File("data/logo.bmp"), CV_LOAD_IMAGE_GRAYSCALE);
        IplImage image = loadAndShowOrExit(new File("data/boldt.jpg"), CV_LOAD_IMAGE_COLOR);

        // Define region of interest that matches the size of the logo
        IplROI roi = new IplROI();
        roi.xOffset(385);
        roi.yOffset(270);
        roi.width(logo.width());
        roi.height(logo.height());

        IplImage imageROI = image.roi(roi);
        // Combine input image with the logo. Mask is used to control blending.
        cvCopy(logo, imageROI, mask);

        // Clear ROI after processing is done.
        // If ROI is not cleared further operations would apply to ROI only.
        // For instance, if saving the image, only part within the ROI would be
        // saved.
        image.roi(null);

        // Display
        show(image, "With Logo");
    }

}
